package com.lanou.connotationjoke.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.ListView;

import de.greenrobot.event.EventBus;

/**
 * Created by dllo on 16/1/20.
 */
public class NewListView extends ListView{
    private float yDown;
    public NewListView(Context context) {
        super(context);
    }

    public NewListView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public NewListView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public NewListView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        switch (ev.getAction()){
            case MotionEvent.ACTION_DOWN:
                yDown = ev.getRawY();
                break;
            case MotionEvent.ACTION_MOVE:
                float yMove = ev.getRawY();
                int distance = (int) (yMove - yDown);
                if (distance >= 30){
                    EventBus.getDefault().post("down");
                }else if (distance <= -30){
                    EventBus.getDefault().post("up");
                }
            break;
            default:
                break;
        }
        return super.onTouchEvent(ev);
    }
}
